package com.wanmait.wanmarecruit.webController;

import com.baidu.ueditor.ActionEnter;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Controller
public class UEditorController {
    @RequestMapping("/static/ueditor-utf8/jsp/upload")
    public void upload(HttpServletRequest request, HttpServletResponse response){

        try {
            request.setCharacterEncoding( "utf-8" );
            response.setHeader("Content-Type" , "text/html");

            String rootPath = request.getServletContext().getRealPath( "/" );
            String action = request.getParameter("action");
            String result =  new ActionEnter( request, rootPath ).exec();
            if("listfile".equals(action) || "listimage".equals(action)){
                rootPath = rootPath.replace("\\","/");
                result = result.replaceAll(rootPath,"/");
            }
            response.getWriter().write( result);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
